package ar.edu.unq.wannaplay.calendareable;

import java.util.ArrayList;
import java.util.List;

import org.joda.time.Interval;

import ar.edu.unq.wannaplay.client.Client;
import ar.edu.unq.wannaplay.employee.Employee;
import ar.edu.unq.wannaplay.employee.Skill;
import ar.edu.unq.wannaplay.entity.Entity;

public class Project extends Entity implements Calendareable {

    private static final long serialVersionUID = 1L;

    private List<Employee> employees = new ArrayList<Employee>();

    private String name;

    private Client client;

    private List<Skill> requirements;

    private Interval interval;

    private int manHour;

    public Project() {
        super();
    }

    public Project(final String name, final Client client, final List<Skill> requirements, final Interval interval) {
        super();
        this.name = name;
        this.client = client;
        this.requirements = requirements;
        this.interval = interval;
    }

    public void addEmployee(final Employee employee) {
        employees.add(employee);
        employee.getRegister().addProject(this);
    }

    // setters y getters
    public List<Employee> getEmployees() {
        return employees;
    }

    public void setEmployees(final List<Employee> employees) {
        this.employees = employees;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(final String name) {
        this.name = name;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(final Client client) {
        this.client = client;
    }

    @Override
    public Interval getInterval() {
        return interval;
    }

    public void setInterval(final Interval interval) {
        this.interval = interval;
    }

    public void setRequirements(final List<Skill> requirements) {
        this.requirements = requirements;
    }

    public List<Skill> getRequirements() {
        return requirements;
    }

    public int getManHour() {
        return manHour;
    }

    public void setManHour(final int manHour) {
        this.manHour = manHour;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || !(obj instanceof Project)) {
            return false;
        }

        Project other = (Project) obj;

        if (this.getId() == other.getId()) {
            return true;
        }
        if ((Integer) this.getId() == null) {
            return false;
        }

        // equivalence by id
        return ((Integer) this.getId()).equals(other.getId());
    }

    @Override
    public int hashCode() {
        if ((Integer) this.getId() != null) {
            return ((Integer) this.getId()).hashCode();
        } else {
            return super.hashCode();
        }
    }
}
